home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / control / server / misc / camera.cs next >
Encoding:
Text File  |  2003-10-26  |  2.8 KB  |  92 lines

  1. //============================================================================
  2. // control/misc/camera.cs
  3. //
  4. //
  5. //  Copyright (c) 2003 by Kenneth C.  Finney.
  6. //============================================================================
  7.  
  8. // Global movement speed that affects all cameras.  This should be moved
  9. // into the camera datablock.
  10. $Camera::movementSpeed = 40;
  11.  
  12.  
  13. datablock CameraData(Observer)
  14. //-----------------------------------------------------------------------------
  15. // Defining a datablock class for an observer camera
  16. //-----------------------------------------------------------------------------
  17. {
  18.    mode = "Observer";
  19. };
  20.  
  21.  
  22. function Observer::onTrigger(%this,%obj,%trigger,%state)
  23. //-----------------------------------------------------------------------------
  24. //
  25. //-----------------------------------------------------------------------------
  26. {
  27.    // state = 0 means that a trigger key was released
  28.    if (%state == 0)
  29.       return;
  30.  
  31.    // Default player triggers: 0=fire 1=altFire 2=jump
  32.    %client = %obj.getControllingClient();
  33.    switch$ (%obj.mode)
  34.    {
  35.       case "Observer":
  36.          // Do something interesting.
  37.  
  38.       case "Death":
  39.          // Viewing dead avatar. The player may want to respawn.
  40.          %client.spawnPlayer();
  41.  
  42.          // Set the camera back into observer mode, since in
  43.          // debug mode we like to switch to it.
  44.          %this.setMode(%obj,"Observer");
  45.    }
  46. }
  47.  
  48. function Observer::setMode(%this,%obj,%mode,%arg1,%arg2,%arg3)
  49. //-----------------------------------------------------------------------------
  50. //
  51. //-----------------------------------------------------------------------------
  52. {
  53.    switch$ (%mode)
  54.    {
  55.       case "Observer":
  56.          // Let the player fly around
  57.          %obj.setFlyMode();
  58.  
  59.       case "Death":
  60.          // Lock the camera down in orbit around the corpse,
  61.          // which should be arg1
  62.          %transform = %arg1.getTransform();
  63.          %obj.setOrbitMode(%arg1, %transform, 0.5, 4.5, 4.5);
  64.  
  65.    }
  66.    %obj.mode = %mode;
  67. }
  68.  
  69.  
  70. //=============================================================================
  71. // Camera methods
  72. //=============================================================================
  73.  
  74.  
  75. function Camera::onAdd(%this,%obj)
  76. //-----------------------------------------------------------------------------
  77. //
  78. //-----------------------------------------------------------------------------
  79. {
  80.    // Default start mode
  81.    %this.setMode(%this.mode);
  82. }
  83.  
  84. function Camera::setMode(%this,%mode,%arg1,%arg2,%arg3)
  85. //-----------------------------------------------------------------------------
  86. //
  87. //-----------------------------------------------------------------------------
  88. {
  89.    // Punt this one over to our datablock
  90.    %this.getDatablock().setMode(%this,%mode,%arg1,%arg2,%arg3);
  91. }
  92.